<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <script th:src="@{/webjars/jquery/3.5.1/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>商品码
            </label>
            <div class="layui-input-inline">
                <input type="text" id="no" name="no" th:value="${WARES_EDIT_BY_NO.getNo()}" lay-verify="required" readonly="readonly"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                商品码不能改变
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>商品名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name" lay-verify="password" th:value="${WARES_EDIT_BY_NO.getName()}"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                商品名长度为3到16个字符
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>商品数量
            </label>
            <div class="layui-input-inline">
                <input type="text" id="number" name="number" lay-verify="required" th:value="${WARES_EDIT_BY_NO.getNumber()}"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                商品数量必须是整数
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>进价
            </label>
            <div class="layui-input-inline">
                <input type="text" id="wares_in" name="wares_in" lay-verify="required" th:value="${WARES_EDIT_BY_NO.getTradePrice()}"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                进价要低于售价
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>售价
            </label>
            <div class="layui-input-inline">
                <input type="text" id="wares_out" name="wares_out" lay-verify="required" th:value="${WARES_EDIT_BY_NO.getRetailPrice()}"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                售价要高于进价
            </div>
        </div>

        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>积分
            </label>
            <div class="layui-input-inline">
                <input type="text" id="points" name="points" lay-verify="required" th:value="${WARES_EDIT_BY_NO.getPoints()}"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                积分值一般为售价的10%
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>状态
            </label>
            <div class="layui-input-inline">
<!--                <input type="text" id="status" name="status" lay-verify="required" th:value="${WARES_EDIT_BY_NO.getWaresStatus()}"-->
<!--                       autocomplete="off" class="layui-input">-->
                <select autocomplete="off" id="status">
                    <dd th:if="${WARES_EDIT_BY_NO.getWaresStatus() == '预警'}">
                        <option value="预警" th:text="${WARES_EDIT_BY_NO.getWaresStatus()}"></option>
                        <option value="正常" >正常</option>
                    </dd>
                    <dd th:if="${WARES_EDIT_BY_NO.getWaresStatus() == '正常'}">
                        <option value="正常" th:text="${WARES_EDIT_BY_NO.getWaresStatus()}"></option>
                        <option value="预警" >预警</option>
                    </dd>
                </select>
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea id="wares_mark" name="wares_mark" placeholder="请输入商品备注" class="layui-textarea"
                          th:text="${WARES_EDIT_BY_NO.getMark()}"></textarea>
            </div>
<!--            <div class="layui-form-mid layui-word-aux">-->
<!--                商品吧-->
<!--            </div>-->
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="add" lay-submit id="submitEdit">
                提交
            </button>
        </div>
    </form>
</div>
<script>

    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;

        //自定义验证规则
        // form.verify({
        //     nikename: function (value) {
        //         if (value.length < 5) {
        //             return '昵称至少得5个字符啊';
        //         }
        //     }
        //     , pass: [/(.+){6,12}$/, '密码必须6到12位']
        //     , repass: function (value) {
        //         if ($('#L_pass').val() != $('#L_repass').val()) {
        //             return '两次密码不一致';
        //         }
        //     }
        // 监听提交
        form.on('submit(add)', function (data) {
            // console.log(data);
            let no = $("#no").val();
            let name = $("#name").val();
            let number = $("#number").val();
            let wares_in = $("#wares_in").val();
            let wares_out = $("#wares_out").val();
            let points = $("#points").val();
            let status = $("#status").val();
            let wares_mark = $("#wares_mark").val();
            // 发异步，把数据提交给后台
            $.ajax({
                url: "editWares",
                type: "PUT",
                data:{
                    no:no,
                    name:name,
                    number:number,
                    tradePrice: wares_in,
                    retailPrice: wares_out,
                    points: points,
                    waresStatus: status,
                    mark: wares_mark
                },
                success: function (resultInfo) {
                    // console.log(resultInfo);
                    layer.alert(resultInfo.message, {icon: 6}, function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    });
                },error:function (e) {
                    // console.log("这里出现了问题！");
                    // console.log(e);
                }

            });
            return false;
        })

    });



</script>
</body>

</html>